var captchaImg = document.getElementById("vcode-img");
function changeCaptcha(){
    var timestamp = new Date().getTime();//生成新的时间戳
    captchaImg.src = "/home/createCaptcha?_t=" + timestamp;
}
function sendCode(){
    var url = "/home/sendCode";
    var username = $("#username").val();
    var vcode = $("#vcode").val();
    var serializeArray = "username="+username+"&vcode="+vcode;
    $.post(url, serializeArray, function (result) {
        if(result.code !== 200) {
            alert(result.msg);
        }else{
            alert("验证码发送成功!");
        }
    });
}

function changelocation(autoredirect){
    window.location.href = autoredirect;
}

function submitLogin(){
    var form = $("#login_form");
    var url = form.attr("action");
    var serializeArray = form.serializeArray();
    $.post(url, serializeArray, function (result) {
        if(result.code !== 200){
            alert(result.msg);
        }else{
            $.dialog({
                width: 200,
                height: 50,
                cache : true,
                radius : false,
                animated : false,
                content : "登录成功,正在跳转中......",
                padding: 10,
            });
            var auUrl = $("#autoredirect").val();
            if(auUrl!='' && auUrl!=null){
                setTimeout("changelocation('"+auUrl+"')",1500 );
            }else{
                setTimeout("changelocation('/home/index')",1500 );
            }

        }
    });
}